class Solution {
    public int minCost(String colors, int[] neededTime) {
        int des=0,scr=1,n=neededTime.length;
        int spentTime=0;
        char []color=colors.toCharArray();
        if(n<2){
            return 0;
        }
        else{
            while(scr<n){
                char a=color[des];
                char b=color[scr];
                if(color[des]==color[scr]){
                    spentTime+=Math.min(neededTime[des],neededTime[scr]);
                if(neededTime[des]>neededTime[scr]) 
                   scr++;
                else
                   des=scr++;
                }
                
                else{
                    des=scr;
                    scr++;
                }
            }
        }
        return spentTime;
    }
}